/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dksoft.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ResourceBundle;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 * Construct Gradient JPanel
 * @author Dickson
 */
public class GradientPanel extends JPanel {

    private Color startColor;
    private Color endColor;
    private String direction;

    /**
     * String color will be property file color key
     * @param String startColor
     * @param String endColor
     * @param String direction, either "V" for vertical or "H" for horizontal
     */
    public GradientPanel(String startColor, String endColor, String direction) {
        this.startColor = Color.decode(ResourceBundle.getBundle("label").getString(startColor));
        this.endColor = Color.decode(ResourceBundle.getBundle("label").getString(endColor));
        this.direction = direction;
    }

    public GradientPanel() {
        this.startColor = Color.decode(ResourceBundle.getBundle("label").getString("gradient.panel.default.start")) ;
        this.endColor = Color.decode(ResourceBundle.getBundle("label").getString("gradient.panel.default.end")) ;
        this.direction = "V";
    }

    @Override
    public void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        GradientPaint gradientPaint;
        if (direction.equals("V") || direction.equals("Vertical")) {
            gradientPaint = new GradientPaint(0, 0, startColor, 0, getHeight(), endColor);
        } else {
            gradientPaint = new GradientPaint(0, 0, startColor, getWidth(), 0, endColor);
        }
        g2d.setPaint(gradientPaint);
        g2d.fillRect(0, 0, getWidth(), getHeight());
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("JCalendar");
        frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        frame.setPreferredSize(new Dimension(410, 180));
        frame.getContentPane().add(new GradientPanel());
        frame.pack();
        frame.setVisible(true);
    }
}
